<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 14-7-30
  Time: 下午1:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    <%@include file="../../../includes/common.jsp" %>
    <title>编辑试题</title>
</head>
<body>
<div id="mainContent">
    <form class="form-horizontal">
        <fieldset>
            <!-- Form Name -->
            <legend></legend>
            <div class="control-group">
                <label class="control-label" for="title">题目</label>

                <div class="controls">
                    <input id="title" name="title" type="text" value="${task.title}">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label">选项</label>

                <div class="controls">
                    <c:forEach var="option" items="${taskOption}">
                        <input name="options" value="${option.optionContent}"/>
                    </c:forEach>
                </div>
            </div>

            <div class="control-group" style="margin-left: 26%">
                试题类型
                <c:forEach var="typeValue" items="${type}">
                    <c:if test='${typeValue.dictCode==task.taskType}' var="judge">
                        <input type="radio" name="taskType" value="${typeValue.dictCode}" checked="checked"/>${typeValue.dictValue}
                    </c:if>
                    <c:if test='${!judge}'>
                        <input type="radio" name="taskType" value="${typeValue.dictCode}"/>${typeValue.dictValue}
                    </c:if>
                </c:forEach>
            </div>
            <div class="control-group">
                <label class="control-label" for="knowledgePoint">知识点</label>

                <div class="controls">
                    <input type="text" id="knowledgePoint" name="knowledgePoint" value="${task.knowledgePoint}"/>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="answer">答案</label>

                <div class="controls">
                    <textarea class="textarea" id="answer" name="answer">${task.answer}</textarea>
                </div>
            </div>
            <div class="control-group">
                <label class="control-label"></label>

                <div class="controls">
                    <input type="button" id="saves" class="btn btn-primary" onclick="save()"
                           value="<spring:message code="save"/>"/>
                    <input type="button" onclick="quit()" class="btn btn-primary"
                           value="<spring:message code="cancel"/>"/>
                </div>
            </div>
        </fieldset>
    </form>
</div>
</body>
</html>
<script type="text/javascript">
    var rules = {
        objInfo: {
            title: {
                checkEmpty: ["title", "题目"]
            },
            knowledgePoint: {
                checkEmpty: ["knowledgePoint", "知识点"]
            },
            answer: {
                checkEmpty: ["answer", "答案"]
            }
        }
    };

    function backFunc(data, returnObj) {
        returnObj.obj = $('#dictName');
        returnObj.errMsg = "题目！";
        if (data == "true") {
            returnObj.bool = true;
        }
        if (data == "false") {
            returnObj.bool = false;
        }
        return returnObj;
    }

    function save() {
        var allBox = $("[name='options']");
        var value = "";
        for (var i = 0; i < allBox.length; i++) {
            value += allBox[i].value + "@#";
        }
        value = value.substring(0, value.length - 2);
        if (!JC.validate(rules)) return;
        $("#saves").button('loading')
        $.ajax({
            url: basePath + "task/library/editLibraryTask",
            data: {
                id: ${task.id},
                taskType: $(":radio:checked").val(),
                title: $("#title").val().trim(),
                collectOptions: value,
                answer: $("#answer").html().trim(),
                knowledgePoint: $("#knowledgePoint").val().trim()
            },
            dataType: "json",
            type: "POST",
            success: function () {
                $.messager.alert("成功", "编辑成功!", "", function () {
                    parent.$("#dataEdit").dialog('close');
                    parent.query();
                });
            },
            error: doError
        })
    }

    function quit() {
        parent.$("#dataEdit").dialog('close');
    }
</script>

